# -*- coding: utf-8 -*-
# @Time    : 2023/7/12 10:02
# @Author  : Pan
# @Software: PyCharm
# @Project : VisualFramework
# @FileName: UNetPlusPlus

image_size = (512, 512)
max_steps = 60000

config = {
    "type": "Image2Image",
    "base_info": {
        "step": max_steps,
        "dot": 100,
        "save_iters": 1000,
        "pretrained": "output/UNet_PlusPlus_PixelShuffle/54000",
        "save_path": "output/UNet_PlusPlus_PixelShuffle",
        "log_dir": "log_dir/UNet_PlusPlus_PixelShuffle",
    },
    "train_dataset": {
        "type": "Image2ImageDataset",
        "batch_size": 8,
        "shuffle": True,
        "num_workers": 2,
        "dt_root": "data/train/image",
        "gt_root": "data/train/groundtruth",
        "transforms": [
            {
                "type": "LoadData",
                "keys": ["img_1", "img_2"],
                "func": "cv2"
            },
            {
                "type": "ResizeByShort",
                "keys": ["img_1", "img_2"],
                "short": [i for i in range(448, 2048, 1)],
                "inter": ["bilinear"]
            },
            {
                "type": "RandPaddingCrop",
                "keys": ["img_1", "img_2"],
                "pad_size": image_size,
                "crop_size": image_size
            },
            {
                "type": "ToTensor",
                "keys": ["img_1", "img_2"],
            },
            # {
            #     "type": "AddGauss",
            #     "keys": ["img_1"]
            # },
            {
                "type": "Normalize",
                "keys": ["img_1", "img_2"],
                "mean": 0.5,
                "std": 0.5
            }
        ]
    },
    "val_dataset": {
        "type": "Image2ImageDataset",
        "batch_size": 4,
        "shuffle": True,
        "num_workers": 2,
        "dt_root": "data/val/image",
        "gt_root": "data/val/groundtruth",
        "transforms": [
            {
                "type": "LoadData",
                "keys": ["img_1", "img_2"],
                "func": "cv2"
            },
            {
                "type": "ResizeByShort",
                "keys": ["img_1", "img_2"],
                "short": [512],
                "inter": ["bilinear"]
            },
            # {
            #     "type": "RandPaddingCrop",
            #     "keys": ["img_1", "img_2"],
            #     "pad_size": image_size,
            #     "crop_size": image_size
            # },
            {
                "type": "ToTensor",
                "keys": ["img_1", "img_2"],
            },
            {
                "type": "Normalize",
                "keys": ["img_1", "img_2"],
                "mean": 0.5,
                "std": 0.5
            }
        ]
    },
    "test_dataset": {
        "type": "Image2ImageDataset",
        "mode": "predict",
        "batch_size": 1,
        "shuffle": True,
        "num_workers": 2,
        "dt_root": "data/val/image",
        "save_root": "output/predict/UNet_PlusPlus_PixelShuffle",
        # "gt_root": "data/val/groundtruth",
        "transforms": [
            {
                "type": "LoadData",
                "keys": ["img"],
                "func": "cv2"
            },
            # {
            #     "type": "ResizeByShort",
            #     "keys": ["img_1", "img_2"],
            #     "short": [512],
            #     "inter": ["bilinear"]
            # },
            # {
            #     "type": "RandPaddingCrop",
            #     "keys": ["img_1", "img_2"],
            #     "pad_size": image_size,
            #     "crop_size": image_size
            # },
            {
                "type": "ToTensor",
                "keys": ["img"],
            },
            {
                "type": "Normalize",
                "keys": ["img"],
                "mean": 0.5,
                "std": 0.5
            }
        ]
    },
    "optimizer": {
        "type": "adam",
        "lr_scheduler": {
            "type": "WarmupCosineLR",    # Warm up 学习率刚开始是由小变大，Cosine
            "learning_rate": 0.0005,
            "total_steps": max_steps,
            "warmup_steps": 500,
            "warmup_start_lr": 1e-8,
            "end_lr": 1e-8
        },
        "decay": None
    },
    "network": {
        "type": "image2image",
        "network": {
            "type": "UNetPlusPlus",
            # "use_deconv": True,
        }
    },
    "loss": {
        "loss_list": [
            {
                "type": "MixLoss",
                "loss_list": [
                    {
                        "type": "L1Loss"
                    },
                    {
                        "type": "PSNRLoss"
                    }
                ],
                "loss_coef": [1, 0.0025]
            }
        ],
        "loss_coef": [1]
    },
    "metric": [
        {
            "type": "PSNR",
        },
        {
            "type": "SSIM",
        },
        {
            "type": "MSSSIM",
        }
    ],
    # "amp": {
    #     "scale": 1024
    # }
}
